package com.coder520.jpa.orders;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class OrderController {
	@Autowired
	private OrderService userService;
	/*@RequestMapping("/hello")
	public String sayHi() {
		return "hi";
	}*/
	@RequestMapping("/all")
	public List<Order> getAllUser(){
		return userService.getAllOrder();
	}
	@RequestMapping("/{id}/orders")//建立具有restful代码风格的好习惯，在boot中，@responsebody源代码进行实现
	public Order getUserById(@PathVariable Long id) {
		Order user=userService.getOrderById(id);
		return user;
	}
	/*
	 * requestMapping默认的跳转方法是get
	 * post方法代表创建一个新的对象
	 */
	@RequestMapping(method=RequestMethod.POST,value="/add")
	public void addUser(@RequestBody Order user) {//建议使用json字符串
		userService.addOrder(user);
	}
	@RequestMapping(method=RequestMethod.PUT,value="/update/{id}")
	public void updateUser(@PathVariable Long id,@RequestBody Order order) {//建议使用json字符串,restful风格代码
		userService.updateOrder(id,order);
	}
	@RequestMapping(value="/del/{id}",method=RequestMethod.DELETE)
	public  void delUser(@PathVariable Long  id) {
		userService.delOrder(id);
	}
}
